/**
 * Created by Ysssssss on 21/1/14.
 */

import apiType, {
    GET_USER_INFO,
    GET_USER_INFO_IN_STORE,
    POST_TICKET_LOGIN,
    GET_BRAND_LIST,
} from "@constants/ActionTypes";
import {setCookie} from "@utils/cookie";

const initialState = {
    accountInfo:{}, //统一账号扫码登录信息
    userInfo: {},
    userInfoInStore: null,
    brandList: [],
}

export default function update(state = initialState, action) {
    const { response, params, payload } = action
    switch (action.type) {
        case apiType(GET_USER_INFO).success:
            return {
                ...state,
                userInfo: {
                    ...response
                }
            }
        case apiType(GET_USER_INFO_IN_STORE).request:
            return {
                ...state,
                userInfoInStore: null
            }
        case apiType(GET_USER_INFO_IN_STORE).success:
            return {
                ...state,
                userInfoInStore: {
                    ...response
                },
                permissionTag: payload.permissionTag
            }
        case apiType(POST_TICKET_LOGIN).success:
            return response.status === 'ok' ? {
                ...state,
                accountInfo: {
                    ...response
                }
            } : state
        case apiType(GET_BRAND_LIST).success:
            return {
                ...state,
                brandList: response.brands
            }
        default:
            return state
    }
}